package com.miku.mq.consume;


import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import static com.miku.constant.MessageConstant.DEAD_LETTER_QUEUE;

@Component
@Slf4j
public class DeadConsume {


    @SneakyThrows
    @RabbitListener(queues = DEAD_LETTER_QUEUE)
    public void doTTLMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag){
        log.info("死信队列消费消息：{}",message);
        //接收到死信队列,处理重新加入到队列
        channel.basicAck(deliveryTag,false);
    }

}
